package com.beerbook;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Beer {
	private int id;
	private String name;
	private String brewery;
	private String category;
	private String style;
	private double abv;
	private double ibu;
	private String date;
	private double rating;
	private String notes;
	private String picture;
	private int categoryId;
	
	public Beer(SQLiteDatabase db, int beerId) {
        Cursor cursor = db.query("beer", new String[] {"_id","name","brewery","category","style","abv","ibu","date","rating","notes","picture"},"_id == "+beerId,null,null,null,null);
        if (cursor.getCount() == 1){
        	cursor.moveToFirst();
        	Cursor cursor2 = db.query("category", new String[] {"_id","category"}, "_id == "+cursor.getString(cursor.getColumnIndex("category")),null,null,null,null);
        	
        	if (cursor2.getCount() == 1){
            	cursor2.moveToFirst();
        		category=cursor2.getString(cursor2.getColumnIndex("category"));
        		categoryId=cursor2.getInt(cursor2.getColumnIndex("_id"));
        	}
        	
        	id=cursor.getInt(cursor.getColumnIndex("_id"));
        	name=cursor.getString(cursor.getColumnIndex("name"));
	        brewery=cursor.getString(cursor.getColumnIndex("brewery"));
	        style=cursor.getString(cursor.getColumnIndex("style"));
	        abv=cursor.getDouble(cursor.getColumnIndex("abv"));
	        ibu=cursor.getDouble(cursor.getColumnIndex("ibu"));
	        date=cursor.getString(cursor.getColumnIndex("date"));
	        rating=cursor.getDouble(cursor.getColumnIndex("rating"));
	        notes=cursor.getString(cursor.getColumnIndex("notes"));
	        picture=cursor.getString(cursor.getColumnIndex("picture"));
        }
	}

    public Beer(String name, String brewery) {
        this.name = name;
        this.brewery = brewery;
    }

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getBrewery() {
		return brewery;
	}

	public void setBrewery(String brewery) {
		this.brewery = brewery;
	}
	
	public int getCategoryId() {
		return categoryId;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public double getAbv() {
		return abv;
	}

	public void setAbv(double abv) {
		this.abv = abv;
	}

	public double getIbu() {
		return ibu;
	}

	public void setIbu(double ibu) {
		this.ibu = ibu;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public double getRating() {
		return rating;
	}

	public void setRating(double rating) {
		this.rating = rating;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public int getId() {
		return id;
	}
}
